﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;

public partial class admin_additems : System.Web.UI.Page
{
    BusinessLogic obj_businesslogic = new BusinessLogic();
    protected void Page_Load(object sender, EventArgs e)
    {
        
            DataTable dt = obj_businesslogic.getitemtypes();
            ddltypes.DataSource = dt;

            ddltypes.DataTextField = "typename";
            ddltypes.DataValueField = "i_autoid";
            ddltypes.DataBind();
 
        
    }
    protected void btninsert_Click(object sender, EventArgs e)
    {
        if (uploadtypeimage.PostedFile != null)
        {
            //save the destination path of the image
            string mymap = MapPath("~/");
            // save the image name into ImageName
            string ImageName = uploadtypeimage.FileName;
            //save the full url of the image with folder name and image name
            string ImageSaveURL = mymap + "Typeimages\\" + ImageName;
            //upload image to the path of image

            uploadtypeimage.PostedFile.SaveAs(ImageSaveURL);
            uploadtypeimage.DataBind();

            string typeimagepath = "~/" + "Typeimages\\" + ImageName;


            if (obj_businesslogic.inserttypedata(typeimagepath, txttypename.Text.ToString()))
            {
                txtitemname.Text = "";
                lblmsg0.Text = "Type Inserted";


            }

        }
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (uploaditemimage.PostedFile != null)
        {
            //save the destination path of the image
            string mymap = MapPath("~/");
            // save the image name into ImageName
            string ItemImageName = uploaditemimage.FileName;
            //save the full url of the image with folder name and image name
            string ImageSave = mymap + "itemimages\\" + ItemImageName;
            //upload image to the path of image

            uploaditemimage.PostedFile.SaveAs(ImageSave);
            uploaditemimage.DataBind();

            string itemimagepath = "~/" + "itemimages\\" + ItemImageName;
            string itemname = txtitemname.Text.ToString();
            int i_refid = Convert.ToInt32(ddltypes.SelectedValue.ToString());

            if (obj_businesslogic.insertitemsdetails(i_refid,itemimagepath,itemname))
            {
                txtitemname.Text = "";
                lblmsg.Text = "Item Inserted";
 
            }


        }
    }
}